import { alovaInstance } from '@/utils/request'
import { LoginRequest, RegisterRequest, LoginResponse, User } from '@/types'
import { API_PATHS, API_CONFIG } from '@/configs'

// 认证相关API

/**
 * 用户登录
 * @param data 登录请求数据
 * @returns 登录响应数据
 */
export const login = async (data: LoginRequest) => {
  const method = alovaInstance.Post<LoginResponse>(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.AUTH.LOGIN}`,
    data
  )
  // 使用send方法执行请求，返回Promise
  return await method.send()
}

/**
 * 用户注册
 * @param data 注册请求数据
 * @returns 注册响应数据
 */
export const register = async (data: RegisterRequest) => {
  const method = alovaInstance.Post<User>(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.AUTH.REGISTER}`,
    data
  )
  // 使用send方法执行请求，返回Promise
  return await method.send()
}
